<template>
  <div class="box">
    <video id="myVideo" autoplay muted loop>
      <source src="@/assets/video.mp4" type="video/mp4">
    </video>
    <!-- card  -->
    <el-card>
      <template #header> <img src="@/assets/logo1.png"></template>
      <el-form ref="loginRef" style="width:40%;" :rules="loginFormRules" :model="loginForm">
        <el-form-item prop="account">
          <el-input v-model="loginForm.account" />
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" placeholder="请输入密码" show-password />
        </el-form-item>
        <el-form-item prop="code">
          <el-input v-model="loginForm.code">
            <template #suffix>
              <img :src="src" alt="" class="keys" @click="getCaptcha">
            </template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="login">登录</el-button>
        </el-form-item>
      </el-form>
      <p>仅用于IT培训教学使用，为保障您的个人信息安全，请勿向平台录入任何个人敏感信息（如手机号、身份证号等）！</p>
    </el-card>

  </div>
</template>

<script>
export default {
  data() {
    return {
      src: '',
      loginForm: {
        account: 'demo',
        password: 'hm#qd@23!',
        code: '',
        key: '1234'
      },
      loginFormRules: {
        account: [
          { required: true, message: '用户名不能为空', trigger: 'blur' },
          { min: 4, max: 11, message: '长度在5到11之间', trigger: 'blur' }

        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 5, max: 11, message: '长度在5到11之间', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '验证码不能为空', trigger: 'blur' }
        ]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined
    }
  },
  created() {
    this.getCaptcha()
  },
  methods: {
    getCaptcha() {
      this.loginForm.key = Math.ceil(Math.random() * 1000)
      this.src = 'https://slwl-api.itheima.net/manager/captcha?key=' + this.loginForm.key
    },
    async login() {
      try {
        await this.$refs.loginRef.validate() // 校验非空
        console.log('二次校验成功')
        // 成功后
        // console.log(this.loginForm)
        await this.$store.dispatch('user/login', this.loginForm)
        this.$message.success('登录成功') // 提示成功
        this.$router.push('/dashboard')
      } catch (e) {
        console.log(e)
        console.log(111)
      }
    }
  }
}
</script>

<style lang="scss">
.box {
  position: relative;
  z-index: 9999999;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  #myVideo {
  position: relative;
   width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
   height: 100%;
   object-fit: fill;
}
.el-card{
  text-align: center;
  position: absolute;
  background-color: #fff;
  width: 450px;
  height: 490px;
  border-radius: 20px;
  .el-input{
    width: 400px;
  }
  .el-button{
    width: 400px;
  }
  .el-card__header{
    border: none;
  }
  img{
    height: 60px;
    margin:0 auto;
  }
  .el-input__inner{
    height: 45px;
  }
  .keys{
      height: 40px;
      margin-top: 3px;
    }
  .el-button{
       background-color: rgb(225, 85, 54);
       height: 54px;
       color: #fff;
       font-size: 20px;
       margin-top: 10px;
  }
  p{
    font-size: 14px;
    text-align: left;
    color:  rgb(225, 85, 54);
    line-height: 1.5;
  }
}
}

</style >
